import http from "./http";

// 返回状态设置为常量
// export const success_code = 20000;
// export const fail_code = 40000;


// 解析 token
export const checkToken = () => {
    return http.requestGet('/user/check/token')
}
// 登录
export const doLogin = (verifyCode, verifyKey, user) => {
    return http.requestPost('/user/login/' + verifyCode + '/' + verifyKey, user);
}



// 分类 - 获取列表
export const categoryList = () => {
    return http.requestGet('/admin/category/list')
}
// 分类 - 删除
export const deleteCategoryById = (categoryId) => {
    return http.requestDelete('/admin/category/' + categoryId)
}
// 分类 - 添加
export const addCategory = (category) => {
    return http.requestPost('/admin/category/', category)
}
// 分类 - 根据ID查询
export const getCategoryById = (categoryId) => {
    return http.requestGet('/admin/category/' + categoryId)
}
// 分类 - 更新
export const updateCategory = (category) => {
    return http.requestPut('/admin/category/', category)
}



// 轮播图 - 条件分页查询列表
export const getLoopList = (current = 1, size = 20, query) => {
    return http.requestGet('/admin/loop/list/' + current + '/' + size, {params: query})
}
// 轮播图 - 添加
export const addLoop = (loop) => {
    return http.requestPost('/admin/loop', loop)
}
// 轮播图 - 删除
export const deleteLoopById = (loopId) => {
    return http.requestDelete('/admin/loop/' + loopId)
}
// 轮播图 - 根据ID查询
export const getLoopById = (loopId) => {
    return http.requestGet('/admin/loop/' + loopId)
}
// 轮播图 - 更新
export const updateLoop = (category) => {
    return http.requestPut('/admin/loop/', category)
}



// 用户 - 条件分页查询列表
// get 传对象要使用 {params: query}
export const getUserList = (current = 1, size = 20, query) => {
    return http.requestGet('/user/list/' + current + '/' + size, {params: query})
}
// 用户 - 删除
export const deleteUserById = (userId) => {
    return http.requestDelete('/user/' + userId)
}
// 用户 - 管理员重置用户密码
// 对应后端方法注解为：
// @PutMapping("/reset/password/{userId}")
// public Result resetPassword(@PathVariable("userId") String userId, @RequestParam("password") String password)
export const resetPassword = (userId, password) => {
    return http.requestPut('/user/reset/password/' + userId + '?password=' + password)
}



// 用户 - 添加
export const addUser = (user) => {
    return http.requestPost('/user', user)
}
// 用户 - 根据ID查询
export const getUserById = (userId) => {
    return http.requestGet('/user/' + userId)
}
// 用户 - 更新
export const updateUser = (user) => {
    return http.requestPut('/user/', user)
}



// 网站设置 - 获取邮箱验证码
export const getVerifyCode = (type, emailAddress) => {
    // /user/verifyCode?type=update&emailAddress=    ( emailAddress 不能写成 email )
    return http.requestGet('/user/verifyCode?type=' + type + '&emailAddress=' + emailAddress)
}
// 网站设置 - 更新用户邮箱地址
export const updateEmail = (email, verifyCody) => {
    return http.requestPut('/user/email?email=' + email + '&verifyCody=' + verifyCody)
}
// 网站设置 - 检查用户名是否已存在
export const checkUsername = (username) => {
    return http.requestGet('/user/username?username=' + username)
}
// 网站设置 - 修改用户信息
export const updateUserInfo = (user) => {
    return http.requestPut('/user/userInfo', user)
}



// 网站信息 - 获取 SEO 信息
export const getSeoInfo = () => {
    return http.requestGet('/admin/web_size_info/seo')
}
// 网站信息 - 获取网站头部信息
export const getWebSizeTitle = () => {
    return http.requestGet('/admin/web_size_info/title')
}
// 网站信息 - 更新网站标题
export const upWebSizeTitle = (title) => {
    return http.requestPut('/admin/web_size_info/title?title=' + title)
}
// 网站信息 - 更新网站SEO信息
export const putSeoInfo = (keyWords, description) => {
    return http.requestPut('/admin/web_size_info/seo?keyWords=' + keyWords + '&description=' + description)
}



// 友情链接 - 获取列表数据
export const getFriendLinks = (query) => {
    return http.requestGet('/admin/friends/list', {params: query})
}
// 友情链接 - 添加
export const addFriendLink = (friendLink) => {
    return http.requestPost('/admin/friends', friendLink)
}
// 友情链接 - 根据ID查询
export const getFriendLink = (friendLinkId) => {
    return http.requestGet('/admin/friends/' + friendLinkId)
}
// 友情链接 - 更新
export const updateFriendLink = (friendLink) => {
    return http.requestPut('/admin/friends', friendLink)
}
// 友情链接 - 删除
export const deleteFriendLink = (friendLinkId) => {
    return http.requestDelete('/admin/friends/' + friendLinkId)
}




// 图片 - 获取列表数据
export const getImageList = (current = 1, size = 20, query) => {
    return http.requestGet('/admin/image/list/' + current + '/' + size, {params: query})
}


// 文章管理 - 发表文章
export const addArticle = (article) => {
    return http.requestPost('/admin/article', article)
}
// 文章管理 - 条件分页列表
export const getArticleList = (current = 1, size = 20, query) => {
    return http.requestGet('/admin/article/list/' + current + '/' + size, {params: query})
}